package com.sp.method;

public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.setName("sp");//设置线程名称
        t.setPriority(Thread.MIN_PRIORITY);//更改优先级
        t.start();//启动子线程

        //主线程打印5 hi, 然后就终端子线程的休眠
        for (int i = 0; i < 5; i++) {
            Thread.sleep(1000);
            System.out.println("hi " + i);
        }

        System.out.println(t.getName() + "线程的优先级: " + t.getPriority());
        t.interrupt();//当执行到这里, 就会中断t线程的休眠

    }
}

class T extends Thread {
    @Override
    public void run() {
        while (true){
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + " 吃包子~~~" + i);
            }
            try {
                System.out.println(Thread.currentThread().getName() + " 休眠中~~~");
                Thread.sleep(20000);//20秒
            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().getName() + "被interrupt了");
            }
        }

    }
}